package com.ksm.zyz.controller;


import com.ksm.zyz.common.base.BaseController;
import com.ksm.zyz.common.base.Global;
import com.ksm.zyz.common.util.DateUtil;
import com.ksm.zyz.sys.entity.ExtData;
import com.ksm.zyz.sys.entity.Message;
import com.ksm.zyz.sys.entity.SysRole;
import com.ksm.zyz.sys.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author litao
 *
 */
@Controller
@RequestMapping("role")
public class SysRoleController extends BaseController<SysRole> {

	@Autowired//自动set
	private SysRoleService sysRoleService;

	@RequestMapping("list")
	@ResponseBody
	public ExtData selectAll(SysRole sysRole, HttpServletRequest req){
		sysRole.setBsData(getBsData(req));
		extData.setList(sysRoleService.selectAll(sysRole));
		extData.setTotalCount(sysRoleService.sysselectCount(sysRole));
		return extData;
	}

	/**
	 * 角色新增
	 * @param sysRole
	 * @return
	 */
	@RequestMapping("create")
	@ResponseBody
	public Message create(SysRole sysRole){
		sysRole.setId(DateUtil.getShortUuid());
		sysRoleService.save(sysRole);
		return new Message(Global.SUCCESSFUL);
	}

	/**
	 * 角色修改
	 * @param sysRole
	 * @return
	 */
	@RequestMapping("update")
	@ResponseBody
	public Message update(SysRole sysRole){
		sysRoleService.update(sysRole);
		return new Message(Global.SUCCESSFUL);
	}

	/**
	 * 角色删除
	 * @return
	 */
	@RequestMapping("delete")
	@ResponseBody
	public Message delete(String ids){
		String[] roleIds = ids.split(",");
		sysRoleService.delete(roleIds);
		return new Message(Global.SUCCESSFUL);
	}


}
